package com.somsoft.handjc.activity.query.xzsp;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import com.somsoft.handjc.activity.MainActivity;
import com.somsoft.handjc.activity.R;
import com.somsoft.handjc.util.MyApplication;
import com.somsoft.handjc.util.Utils;
import com.somsoft.handjc.util.XzspDataUtil;
/**
 * 行政审批  详细页面  监察信息
 * 
 * @author Administrator
 * 
 */
@SuppressWarnings("all")
public class XzspDetailJcInfoActivity extends ListActivity {

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MyApplication.getInstance().addActivity(this);
		setTitle("行政审批--业务明细--监察信息");
		List<Map<String, Object>> listItem = new ArrayList<Map<String, Object>>();
		try {
			listItem = getData(getIntent());
		} catch (Exception e) {
			Toast.makeText(XzspDetailJcInfoActivity.this, "加载数据失败！", Toast.LENGTH_SHORT).show();
		}
			
		SimpleAdapter listItemAdapter = new SimpleAdapter(this, listItem, R.layout.common_detail, 
				new String[] { "commonDetail" },
				new int[] { R.id.commonDetail });
		setListAdapter(listItemAdapter);
		Utils.closeLoading();
	}

	
	private List<Map<String, Object>> getData(Intent it) throws Exception{
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		if(it!=null){
			String ywlsh = it.getStringExtra("ywlsh");
			if(ywlsh != null){
				params.add(new BasicNameValuePair("ywlsh",ywlsh));
			}
		}
		
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		try {
			JSONArray array = XzspDataUtil.detailJcInfo(params);
			Map<String, Object> map = null;
			for(int i = 0; i < array.length(); i++){
				JSONObject obj = array.getJSONObject(i);
				map = new HashMap<String, Object>(); 
				String content = "";
				content += "监察类型："+obj.getString("LOGTYPE")+"\n";
				content += "监察子类型："+obj.getString("SUBTYPE")+"\n";
				content += "监察时间："+obj.getString("LOGTIME")+"\n";
				content += "监察结果："+obj.getString("MESSAGE");
				
				map.put("commonDetail", content);
				list.add(map);
			}
		} catch (Exception e) {
			throw e;
		}
		return list;

	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {			
		menu.add(Menu.NONE, 10, 10, "首页").setIcon(android.R.drawable.ic_menu_compass);
		menu.add(Menu.NONE, 90, 90, "退出").setIcon(android.R.drawable.ic_menu_close_clear_cancel);
		return true;											
	}
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {		// 选中某个菜单项
		Intent it = null;
		switch (item.getItemId()) {								// 判断菜单项ID
		case  10:
			it = new Intent(XzspDetailJcInfoActivity.this,MainActivity.class);
			startActivity(it);
			break;
		case  90:
			MyApplication.getInstance().exit();
			break;
		}
		return false;
	}
}
